package com.lyu.travel.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ProjectName: [travel]
 * @Package: [com.lyu.travel.config]
 * @ClassName: [LoginHandlerInterceptor]
 * @Description: 登录拦截器
 * @Author: [78483]
 * @CreateDate: [2020-06-11 20:12]
 * @UpdateUser: [78483]
 * @UpdateDate: [2020-06-11 20:12]
 * @UpdateRemark: [说明本次修改内容]
 * @Version: [v1.0]
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //检测去session能否获得"user"这个值，获得就是登录成功
        Object user=request.getSession().getAttribute("user");
        if (null==user){
            request.getRequestDispatcher("/").forward(request,response);
            return false;
        }
        return true;
    }
}
